package com.shujia.wyh.day28;

import java.lang.reflect.Proxy;

/*
    动态代理
 */
public class Test {
    public static void main(String[] args) {
        UserDaoImpl userDao = new UserDaoImpl();
//        userDao.add();
//        userDao.delete();

        UserDao p = (UserDao)Proxy.newProxyInstance(userDao.getClass().getClassLoader(),
                userDao.getClass().getInterfaces(),
                new InvocationHandlerImpl(userDao));

        p.add();
        p.delete();
        p.update();
        p.select();

        System.out.println("===========================");
        TeacherDaoImpl teacherDao = new TeacherDaoImpl();

        InvocationHandlerImpl invocationHandler = new InvocationHandlerImpl(teacherDao);
        TeacherDao t = (TeacherDao)Proxy.newProxyInstance(teacherDao.getClass().getClassLoader(), teacherDao.getClass().getInterfaces()
                , invocationHandler);
        t.login();
        t.zhuce();


    }
}
